package com.greenzebras.geocache;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;

import com.greenzebras.geocache.cachedata.CacheType;

public class GeocacheSearchFormActivity extends Activity {
	
	static final int SEARCH_EXECUTE = 1;
	
	// Constructor
	public GeocacheSearchFormActivity() {
	}
	
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.search_form);
		
		((Button) findViewById(R.id.search_button)).setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				
				// Create the Search intent
				Intent searchExecuteIntent = new Intent(GeocacheSearchFormActivity.this, GeocacheSearchActivity.class);
				searchExecuteIntent.putExtra("search_form", true);
				
				ArrayList<String> cacheTypeFilter = new ArrayList<String>();
				if (((CheckBox) findViewById(R.id.type_traditional)).isChecked()) {
					cacheTypeFilter.add(CacheType.TRADITIONAL.toString());
				}
				if (((CheckBox) findViewById(R.id.type_project_ape)).isChecked()) {
					cacheTypeFilter.add(CacheType.PROJECT_A_P_E.toString());
				}
				if (((CheckBox) findViewById(R.id.type_mystery_puzzle)).isChecked()) {
					cacheTypeFilter.add(CacheType.MYSTERY_OR_PUZZLE.toString());
				}
				if (((CheckBox) findViewById(R.id.type_letterbox_hybrid)).isChecked()) {
					cacheTypeFilter.add(CacheType.LETTERBOX_HYBRID.toString());
				}
				if (((CheckBox) findViewById(R.id.type_event)).isChecked()) {
					cacheTypeFilter.add(CacheType.EVENT.toString());
				}
				if (((CheckBox) findViewById(R.id.type_custom)).isChecked()) {
					cacheTypeFilter.add(CacheType.CUSTOM.toString());
				}
				
				searchExecuteIntent.putExtra("cacheTypes", cacheTypeFilter);
				startActivity(searchExecuteIntent);
			} // end Save button onClick
		}); // end Save button setOnClickListener
	}

} // end class GeocacheSearchFormActivity
